package com.taru.order.service;

import com.taru.order.common.Data;
import com.taru.order.dao.UserDaoimpl;
import com.taru.order.entity.Articl;
import com.taru.order.entity.Love;
import com.taru.order.entity.User;

import java.util.List;

public class UserService {
    /**
     * 注册用户
     * @param user
     * @return
     */
    public int register(User user) {
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn = userDaoimpl.register(user);
        return isn;
    }
    /**
     * 用户登录
     */
    public User login(String username,String password){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        User user=userDaoimpl.login(username,password);
        return user;
    }
    /**
     * 查询用户信息
     */
    public User userInfo(String user_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        User user=userDaoimpl.userInfo(user_id);
        return user;
    }
    /**
     * 通过user_id修改头像
     */
    public int changeUser(User user){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.changeUser(user);
        return isn;
    }

    /**
     * 添加简介
     */
    public int addBrief(String user_id,String brief){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.addBrief(user_id,brief);
        return isn;
    }
    /**
     * 用户收藏文章
     */
    public int collectArticl(String user_id,String articl_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.collectArticl(user_id,articl_id);
        return isn;
    }
    /**
     * 用户取消收藏文章
     */
    public int noCollectArticl(String user_id,String articl_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.noCollectArticl(user_id,articl_id);
        return isn;
    }
    /**
     * 查询收藏的文章
     */
    public List<Articl> selectCollect(String user_id){
        UserDaoimpl userDaoimpl=new UserDaoimpl();
        List<Articl> articl=userDaoimpl.selectCollect(user_id);
        return articl;
    }
    /**
     * 用户关注用户
     */
    public int attentionUser(String user_id,String love_user_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.attentionUser(user_id,love_user_id);
        return isn;
    }
    /**
     * 用户取消关注用户
     */
    public int noAttentionUser(String user_id,String love_user_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.noAttentionUser(user_id,love_user_id);
        return isn;
    }
    /**
     * 查询关注的用户
     */
    public List<User> selectLove(String user_id){
        UserDaoimpl userDaoimpl=new UserDaoimpl();
        List<User> user=userDaoimpl.selectLove(user_id);
        return user;
    }
    /**
     * 被关注时粉丝数量增加
     */
    public int fansNumber(String user_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.fansNumber(user_id);
        return isn;
    }
    /**
     * 被取消关注时粉丝数量减少
     */
    public int fansNumberLose(String user_id){
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        int isn=userDaoimpl.fansNumberLose(user_id);
        return isn;
    }
    /**
     * 查询粉丝数量前20的用户
     */
    public List<User> selectLoveMax(String userId){
        UserDaoimpl userDaoimpl=new UserDaoimpl();
        List<User> user=userDaoimpl.selectLoveMax(userId);
        return user;
    }
    /**
     * 分页查询用户
     */
    public Data listUsers(Integer pageNum, Integer pageSize){
        UserDaoimpl userDaoimpl=new UserDaoimpl();
        List<User> userList=userDaoimpl.listUsers(pageNum,pageSize);
        Long toralCount=userDaoimpl.queryToral();
        Data data=new Data();
        data.setTotalCount(toralCount);
        data.setTotalPage(toralCount,pageSize);
        data.setPageNum(pageNum);
        data.setPageSize(pageSize);
        data.setList(userList);
        return data;
    }
    /**
     * 判断用户关注用户
     */
    public boolean queryuserLike(Love love){
        UserDaoimpl userDaoimpl=new UserDaoimpl();
        Love love1=userDaoimpl.queryuserLike(love);
        boolean isExist=false;
        if(love1 !=null){
            isExist=true;
        }
        return isExist;
    }
}
